package com.gitee.wsl.struct.grammar.node.expr.value

import com.gitee.wsl.struct.grammar.node.ASTNode
import com.gitee.wsl.struct.grammar.node.expr.IExp
import com.gitee.wsl.struct.grammar.node.expr.closure.IClosureScope
import com.gitee.wsl.struct.grammar.node.expr.semantic.ISemanticRecorder
import com.gitee.wsl.struct.grammar.node.expr.type.TokenType

/**
 * 【语义分析】基本操作数
 *
 * @author bajdcc
 */
class ExpValue(var token: ASTNode) : IExp {

    override fun isConstant(): Boolean {
        return false
        //return token.type !== TokenType.ID
    }

    override fun isEnumerable(): Boolean {
        return false
    }

    override fun simplify(recorder: ISemanticRecorder): IExp {
        return this
    }

    override fun analysis(recorder: ISemanticRecorder) {

    }

    /*override fun genCode(codegen: ICodegen) {
        codegen.genCode(RuntimeInst.ipush, codegen.genDataRef(token.obj!!))
        if (token.type !== TokenType.ID) {
            codegen.genCode(RuntimeInst.iload)
        } else {
            if (TokenTools.isExternalName(token)) {
                codegen.genCode(RuntimeInst.iloadx)
            } else {
                codegen.genCode(RuntimeInst.iloadv)
            }
        }
    }*/

    override fun toString(): String {
        return token.toString()
    }

    override fun print(prefix: StringBuilder): String {
        return toString()
    }

    override fun addClosure(scope: IClosureScope) {
        /*if (token.type === TokenType.ID) {
            scope.addRef(token.obj!!)
        }*/
    }

    override fun setYield() {

    }
}